/*
 * 项目的配置信息
 *
 * @Author:
 * @Date:  
 * @Wechat: 
 * @Email: 
 * @Copyright 
 */
import { defineStore } from 'pinia';
import { appDefaultConfig } from '../../../theme/app-config';
import { lxSentry } from '/@/lib/lx-sentry';
import { getAppConfig, setAppConfig, removeAppConfig } from "/@/utils/storage";

let state = {
  ...appDefaultConfig
};

let appConfigStr = appDefaultConfig;
let language = appDefaultConfig.language;
if (appConfigStr) {
  try {
    language = state.language;
  } catch (e) {
    lxSentry.captureError(e);
  }
}

/**
 * 获取初始化的语言
 */
export const getInitializedLanguage = function () {
  return language;
};

export const useAppConfigStore = defineStore({
  id: 'appConfig',
  state: () => ({
    // 读取config下的默认配置
    ...state,
    // 全屏
    fullScreenFlag: false,
  }),
  actions: {
    reset() {
      for (const k in appDefaultConfig) {
        this[k] = appDefaultConfig[k];
      }
    },
    showHelpDoc() {
      this.helpDocExpandFlag = true;
    },
    hideHelpDoc() {
      this.helpDocExpandFlag = false;
    },
    startFullScreen() {
      this.fullScreenFlag = true;
    },
    exitFullScreen() {
      this.fullScreenFlag = false;
    },
    setAppConfig(appConfig) {
      setAppConfig(appConfig);
    }
  },
});
